
def max_sub(N,raw):
    max_sum =This_sum = 0
    ans = []

    for i in range(0,N):
        This_sum += raw[i]
        if This_sum > max_sum:
            max_sum =This_sum
            ans.append(i)
        elif This_sum<0:
            This_sum = 0
    a,b = read_seq(ans,raw)
    return max_sum,a,b

def read_seq(ans,raw):
    try:
        a = raw[ans[0]]
        b = raw[ans[-1]]
        return a,b
    except:
        return 0,0

if __name__ == '__main__':
    N = int(input())
    raw = []
    raw = [int(n) for n in input().split()]
    print(max_sub(N,raw)[0],end=' ')
    if max_sub(N, raw)[1]|max_sub(N, raw)[2] ==0:
        print(0,end='')
    else:
        if max_sub(N, raw)[1]>0:
            print(max_sub(N, raw)[1],end=' ')
        else:print(raw[0],end=' ')
        if max_sub(N, raw)[2] > 0:
            print(max_sub(N, raw)[2], end='')
        else:
            print(raw[-1], end='')
